package com.ecommerce.chat.dto;

import lombok.Data;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 前端聊天响应结果
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "AI客服聊天响应")
public class ChatResponse {
    
    /**
     * AI回复内容
     */
    @ApiModelProperty(value = "AI回复内容", example = "您好！我是智能客服，很高兴为您服务。请问有什么可以帮助您的吗？")
    private String reply;
    
    /**
     * 会话ID
     */
    @ApiModelProperty(value = "会话ID", example = "session_123456")
    private String sessionId;
    
    /**
     * 响应时间戳
     */
    @ApiModelProperty(value = "响应时间戳", example = "1640995200000")
    private Long timestamp;
    
    /**
     * 是否成功
     */
    @ApiModelProperty(value = "是否成功", example = "true")
    @Builder.Default
    private Boolean success = true;
    
    /**
     * 错误信息（失败时返回）
     */
    @ApiModelProperty(value = "错误信息", example = "")
    private String errorMessage;
    
    /**
     * Token使用情况（可选）
     */
    @ApiModelProperty(value = "Token使用情况")
    private TokenUsage tokenUsage;
    
    /**
     * Token使用统计
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class TokenUsage {
        
        @ApiModelProperty(value = "输入Token数", example = "10")
        private Integer inputTokens;
        
        @ApiModelProperty(value = "输出Token数", example = "25")
        private Integer outputTokens;
        
        @ApiModelProperty(value = "总Token数", example = "35")
        private Integer totalTokens;
    }
    
    /**
     * 创建成功响应
     */
    public static ChatResponse success(String reply, String sessionId) {
        return ChatResponse.builder()
                .reply(reply)
                .sessionId(sessionId)
                .timestamp(System.currentTimeMillis())
                .success(true)
                .build();
    }
    
    /**
     * 创建失败响应
     */
    public static ChatResponse error(String errorMessage, String sessionId) {
        return ChatResponse.builder()
                .sessionId(sessionId)
                .timestamp(System.currentTimeMillis())
                .success(false)
                .errorMessage(errorMessage)
                .build();
    }
}